package com.igeek.clud_system.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.igeek.clud_system.condition.DruidCondition;
import com.igeek.clud_system.property.DruidProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DruidProperties.class)
public class DruidConfiguration {

    @Bean
    @Conditional(DruidCondition.class)
    public DruidDataSource getDruidDataSource(DruidProperties properties){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl(properties.getUrl());
        druidDataSource.setDriverClassName(properties.getDriverClassName());
        druidDataSource.setUsername(properties.getUsername());
        druidDataSource.setPassword(properties.getPassword());
        druidDataSource.setMaxActive(properties.getMaxActive());
        druidDataSource.setMinIdle(properties.getMinIdle());
        druidDataSource.setInitialSize(properties.getInitialSize());
        return druidDataSource;
    }
}
